import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn } from "typeorm";
import { ManualTimestamp } from "../decorators/manual-timestamp.decorator";
import { FactionEntity } from "./faction.entity";
import { CharacterEntity } from "./character.entity";

@Entity("faction_members")
@ManualTimestamp()
export class FactionMemberEntity {
  @PrimaryGeneratedColumn()
  id!: number;

  @Column({ type: "bigint", comment: "帮派ID" })
  factionId!: number;

  @Column({ type: "bigint", comment: "角色ID" })
  characterId!: number;

  @Column({
    type: "int",
    default: 2,
    comment: "成员角色(0:不是成员,1:准成员,2:成员,3:管理,4:帮主)",
  })
  role!: number;

  @Column({ type: "bigint", default: 0, comment: "贡献度" })
  contribution!: number;

  @Column({
    type: "datetime",
    comment: "加入时间",
  })
  joinDate!: Date;

  @Column({ type: "datetime", nullable: true, comment: "最后活跃时间" })
  lastActive!: Date;

  @Column({ type: "tinyint", default: 1, comment: "状态(1:正常,0:离线)" })
  status!: number;

  @Column("datetime", { name: "created_at", comment: "创建时间" })
  created_at!: Date;

  @Column("datetime", { name: "updated_at", nullable: true, comment: "更新时间" })
  updated_at!: Date | null;

  // 关联关系
  @ManyToOne(() => FactionEntity, (faction) => faction.members, {
    eager: false,
  })
  @JoinColumn({ name: "factionId" })
  faction!: FactionEntity;

  @ManyToOne(() => CharacterEntity, { eager: false })
  @JoinColumn({ name: "characterId" })
  character!: CharacterEntity;
}
